<template>
  <div style='position:fixed;top:0px;left:0px;right:0px;bottom:0px;background-image: url("/star1.png");'>
    <div id='login'>
      <el-form :model='loginForm'
               ref='loginForm'>
        <h2 style='color:white;text-align:center;'>员工登录</h2>
        <el-form-item>
          <el-input v-model='loginForm.username'
                    name='username'
                    placeholder='请输入用户名'></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model='loginForm.password'
                    name='password'
                    type='password'
                    placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item style='position:absolute;bottom:10px;left:40%;'>
          <el-button type='primary'
                     @click='handleLogin'>登录</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
</template>

<script>
import $ from "jquery";
export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: '',
      }
    }
  },
  methods: {
    handleLogin () {
      let config = {
        headers: {
          "Content-Type": "multipart/form-data"
        }
      };
      let param = { name: this.loginForm.username, pwd: this.loginForm.password };
      $.post("http://172.16.0.233:8011/api/Login/HRLogin", param, function (data) {
        console.log(data);
        if (data.message != "") {
          alert(data.message);
          return;
        }
        if (data.state == "success" && data.message == "") {
          var Authorization = data.data.Authorization;
          document.cookie = 'Authorization=' + Authorization + '|' + 'username=' + param.name;
          let HRJobNo = document.cookie.split('|')[1].split(';')[0].split('=')[1]
          console.log(HRJobNo)
          setTimeout(function () {
            window.location.href = "/adminindex";
          }, 300)
        }
        else {
          $.alert(data.message);
        }
      }, "json");
    }
  }
};
</script>

<style>
.el-input {
  width: 300px;
}
#login {
  position: absolute;
  top: 20%;
  left: 50%;
  background-color: rgba(255, 255, 255, 0.3);
  width: 400px;
  height: 240px;
  padding: 20px 30px;
  border-radius: 5px;
  margin-left: -230px;
}
</style>
